import*as e from"../../core/sdk/sdk.js";import*as t from"../../core/i18n/i18n.js";import*as i from"../../ui/legacy/legacy.js";import*as n from"../../core/common/common.js";import*as o from"../sources/sources.js";import*as s from"../event_listeners/event_listeners.js";const r=new CSSStyleSheet;r.replaceSync(':host{margin:0;padding:2px 4px;min-height:18px}.tree-outline{padding:0}.tree-outline li{margin-left:14px;user-select:text}.tree-outline li.parent{margin-left:1px}.tree-outline li:not(.parent)::before{display:none}.breakpoint-hit{--override-breakpoint-hit-background-color:rgb(255 255 194);--override-breakpoint-hit-border-color:rgb(107 97 48);background-color:var(--override-breakpoint-hit-background-color)}:host-context(.-theme-with-dark-background) .breakpoint-hit{--override-breakpoint-hit-background-color:hsl(46deg 98% 22%);--override-breakpoint-hit-dark-mode-color:#ccc;color:var(--override-breakpoint-hit-dark-mode-color)}.breakpoint-hit .breakpoint-hit-marker{background-color:var(--override-breakpoint-hit-background-color);border-right:3px solid var(--override-breakpoint-hit-border-color);height:100%;left:0;margin-left:-30px;position:absolute;right:-4px;z-index:-1}.source-code[is="dt-checkbox"]{max-width:100%}\n/*# sourceURL=categorizedBreakpointsSidebarPane.css */\n');const a={breakpointHit:"breakpoint hit"},l=t.i18n.registerUIStrings("panels/browser_debugger/CategorizedBreakpointsSidebarPane.ts",a),d=t.i18n.getLocalizedString.bind(void 0,l);class c extends i.Widget.VBox{#e;#t;#i;#n;#o;#s;constructor(t,n,o,s){super(!0),this.#e=new i.TreeOutline.TreeOutlineInShadow,this.#e.setShowSelectionOnKeyboardFocus(!0),this.contentElement.appendChild(this.#e.element),this.#t=o,this.#i=s,this.#n=new Map;for(const e of t)this.#n.has(e)||this.createCategory(e);if(t.length>0){const e=this.#n.get(t[0]);e&&e.element.select()}this.#o=new Map;for(const e of n)this.createBreakpoint(e);e.TargetManager.TargetManager.instance().addModelListener(e.DebuggerModel.DebuggerModel,e.DebuggerModel.Events.DebuggerPaused,this.update,this),e.TargetManager.TargetManager.instance().addModelListener(e.DebuggerModel.DebuggerModel,e.DebuggerModel.Events.DebuggerResumed,this.update,this),i.Context.Context.instance().addFlavorChangeListener(e.Target.Target,this.update,this)}get categories(){return this.#n}get breakpoints(){return this.#o}focus(){this.#e.forceSelect()}handleSpaceKeyEventOnBreakpoint(e,t){e&&" "===e.key&&(t&&t.checkbox.click(),e.consume(!0))}createCategory(e){const t=i.UIUtils.CheckboxLabel.create(e);t.checkboxElement.addEventListener("click",this.categoryCheckboxClicked.bind(this,e),!0),t.checkboxElement.tabIndex=-1;const n=new i.TreeOutline.TreeElement(t);n.listItemElement.addEventListener("keydown",(t=>{this.handleSpaceKeyEventOnBreakpoint(t,this.#n.get(e))})),t.checkboxElement.addEventListener("keydown",(t=>{n.listItemElement.focus(),this.handleSpaceKeyEventOnBreakpoint(t,this.#n.get(e))})),i.ARIAUtils.setChecked(n.listItemElement,!1),this.#e.appendChild(n),this.#n.set(e,{element:n,checkbox:t.checkboxElement})}createBreakpoint(e){const t=i.UIUtils.CheckboxLabel.create(e.title());t.classList.add("source-code"),t.checkboxElement.addEventListener("click",this.breakpointCheckboxClicked.bind(this,e),!0),t.checkboxElement.tabIndex=-1;const n=new i.TreeOutline.TreeElement(t);n.listItemElement.addEventListener("keydown",(t=>{this.handleSpaceKeyEventOnBreakpoint(t,this.#o.get(e))})),t.checkboxElement.addEventListener("keydown",(t=>{n.listItemElement.focus(),this.handleSpaceKeyEventOnBreakpoint(t,this.#o.get(e))})),i.ARIAUtils.setChecked(n.listItemElement,!1),n.listItemElement.createChild("div","breakpoint-hit-marker");const o=this.#n.get(e.category());o&&o.element.appendChild(n),this.#o.set(e,{element:n,checkbox:t.checkboxElement})}getBreakpointFromPausedDetails(e){return null}update(){const t=i.Context.Context.instance().flavor(e.Target.Target),n=t?t.model(e.DebuggerModel.DebuggerModel):null,o=n?n.debuggerPausedDetails():null;if(!o||o.reason!==this.#i||!o.auxData)return void(this.#s&&(i.ARIAUtils.setDescription(this.#s,""),this.#s.classList.remove("breakpoint-hit"),this.#s=void 0));const s=this.getBreakpointFromPausedDetails(o);if(!s)return;i.ViewManager.ViewManager.instance().showView(this.#t);const r=this.#n.get(s.category());r&&r.element.expand();const l=this.#o.get(s);l&&(this.#s=l.element.listItemElement,i.ARIAUtils.setDescription(this.#s,d(a.breakpointHit)),this.#s.classList.add("breakpoint-hit"))}categoryCheckboxClicked(e){const t=this.#n.get(e);if(!t)return;const n=t.checkbox.checked;i.ARIAUtils.setChecked(t.element.listItemElement,n);for(const[t,o]of this.#o)if(t.category()===e){const e=this.#o.get(t);e&&(e.checkbox.checked=n,this.toggleBreakpoint(t,n),i.ARIAUtils.setChecked(o.element.listItemElement,n))}}toggleBreakpoint(e,t){e.setEnabled(t)}breakpointCheckboxClicked(e){const t=this.#o.get(e);if(!t)return;this.toggleBreakpoint(e,t.checkbox.checked),i.ARIAUtils.setChecked(t.element.listItemElement,t.checkbox.checked);let n=!1,o=!1;for(const t of this.#o.keys())t.category()===e.category()&&(t.enabled()?n=!0:o=!0);const s=this.#n.get(e.category());s&&(s.checkbox.checked=n,s.checkbox.indeterminate=n&&o,s.checkbox.indeterminate?i.ARIAUtils.setCheckboxAsIndeterminate(s.element.listItemElement):i.ARIAUtils.setChecked(s.element.listItemElement,n))}wasShown(){super.wasShown(),this.#e.registerCSSFiles([r])}}let h;class p extends c{constructor(){const t=e.DOMDebuggerModel.DOMDebuggerManager.instance().cspViolationBreakpoints(),i=t.map((e=>e.category()));i.sort(),super(i,t,"sources.cspViolationBreakpoints","CSPViolation")}static instance(){return h||(h=new p),h}getBreakpointFromPausedDetails(t){const i=t.auxData&&t.auxData.violationType?t.auxData.violationType:"",n=e.DOMDebuggerModel.DOMDebuggerManager.instance().cspViolationBreakpoints().find((e=>e.type()===i));return n||null}toggleBreakpoint(t,i){t.setEnabled(i),e.DOMDebuggerModel.DOMDebuggerManager.instance().updateCSPViolationBreakpoints()}}var b=Object.freeze({__proto__:null,CSPViolationBreakpointsSidebarPane:p});const k=new CSSStyleSheet;k.replaceSync(".breakpoint-list{padding-bottom:3px}.breakpoint-list .dom-breakpoint > div{overflow:hidden;text-overflow:ellipsis}.breakpoint-entry{display:flex;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;padding:2px 0}.breakpoint-entry:focus-visible{background-color:var(--legacy-focus-bg-color)}.breakpoint-list .breakpoint-entry:hover{background-color:var(--color-background-elevation-2)}.breakpoint-hit{background-color:var(--color-background-elevation-2);border-right:3px solid var(--color-details-hairline);color:var(--color-text-primary)}@media (forced-colors: active){.breakpoint-entry:focus-visible,\n  .breakpoint-list .breakpoint-entry:hover{forced-color-adjust:none;background-color:Highlight}.breakpoint-entry:focus-visible *,\n  .breakpoint-list .breakpoint-entry:hover *{color:HighlightText}}\n/*# sourceURL=domBreakpointsSidebarPane.css */\n");const g={noBreakpoints:"No breakpoints",domBreakpointsList:"DOM Breakpoints list",sS:"{PH1}: {PH2}",sSS:"{PH1}: {PH2}, {PH3}",checked:"checked",unchecked:"unchecked",sBreakpointHit:"{PH1} breakpoint hit",breakpointHit:"breakpoint hit",revealDomNodeInElementsPanel:"Reveal DOM node in Elements panel",removeBreakpoint:"Remove breakpoint",removeAllDomBreakpoints:"Remove all DOM breakpoints",subtreeModified:"Subtree modified",attributeModified:"Attribute modified",nodeRemoved:"Node removed",breakOn:"Break on",breakpointRemoved:"Breakpoint removed",breakpointSet:"Breakpoint set"},u=t.i18n.registerUIStrings("panels/browser_debugger/DOMBreakpointsSidebarPane.ts",g),m=t.i18n.getLocalizedString.bind(void 0,u),v=t.i18n.getLazilyComputedLocalizedString.bind(void 0,u);let M;class f extends i.Widget.VBox{elementToCheckboxes;#r;#o;#a;#l;constructor(){super(!0),this.elementToCheckboxes=new WeakMap,this.#r=this.contentElement.createChild("div","gray-info-message"),this.#r.textContent=m(g.noBreakpoints),this.#o=new i.ListModel.ListModel,this.#a=new i.ListControl.ListControl(this.#o,this,i.ListControl.ListMode.NonViewport),this.contentElement.appendChild(this.#a.element),this.#a.element.classList.add("breakpoint-list","hidden"),i.ARIAUtils.markAsList(this.#a.element),i.ARIAUtils.setLabel(this.#a.element,m(g.domBreakpointsList)),this.#r.tabIndex=-1,e.TargetManager.TargetManager.instance().addModelListener(e.DOMDebuggerModel.DOMDebuggerModel,e.DOMDebuggerModel.Events.DOMBreakpointAdded,this.breakpointAdded,this),e.TargetManager.TargetManager.instance().addModelListener(e.DOMDebuggerModel.DOMDebuggerModel,e.DOMDebuggerModel.Events.DOMBreakpointToggled,this.breakpointToggled,this),e.TargetManager.TargetManager.instance().addModelListener(e.DOMDebuggerModel.DOMDebuggerModel,e.DOMDebuggerModel.Events.DOMBreakpointsRemoved,this.breakpointsRemoved,this);for(const t of e.TargetManager.TargetManager.instance().models(e.DOMDebuggerModel.DOMDebuggerModel)){t.retrieveDOMBreakpoints();for(const e of t.domBreakpoints())this.addBreakpoint(e)}this.#l=null,this.update()}static instance(){return M||(M=new f),M}createElementForItem(e){const t=document.createElement("div");t.classList.add("breakpoint-entry"),t.addEventListener("contextmenu",this.contextMenu.bind(this,e),!0),i.ARIAUtils.markAsListitem(t),t.tabIndex=-1;const o=i.UIUtils.CheckboxLabel.create(void 0,e.enabled),s=o.checkboxElement;s.addEventListener("click",this.checkboxClicked.bind(this,e),!1),s.tabIndex=-1,this.elementToCheckboxes.set(t,s),t.appendChild(o),t.addEventListener("keydown",(e=>{" "===e.key&&(o.checkboxElement.click(),e.consume(!0))}));const r=document.createElement("div");r.classList.add("dom-breakpoint"),t.appendChild(r);const a=document.createElement("div"),l=x.get(e.type);a.textContent=l?l():null;const d=l?l():"";i.ARIAUtils.setLabel(s,d);const c=e.enabled?m(g.checked):m(g.unchecked),h=document.createElement("monospace");return h.style.display="block",r.appendChild(h),n.Linkifier.Linkifier.linkify(e.node,{preventKeyboardFocus:!0,tooltip:void 0}).then((e=>{h.appendChild(e),i.ARIAUtils.setLabel(s,m(g.sS,{PH1:d,PH2:e.deepTextContent()})),i.ARIAUtils.setLabel(t,m(g.sSS,{PH1:d,PH2:e.deepTextContent(),PH3:c}))})),r.appendChild(a),e===this.#l?(t.classList.add("breakpoint-hit"),i.ARIAUtils.setDescription(t,m(g.sBreakpointHit,{PH1:c})),i.ARIAUtils.setDescription(s,m(g.breakpointHit))):i.ARIAUtils.setDescription(t,c),this.#r.classList.add("hidden"),this.#a.element.classList.remove("hidden"),t}heightForItem(e){return 0}isItemSelectable(e){return!0}updateSelectedItemARIA(e,t){return!0}selectedItemChanged(e,t,i,n){i&&(i.tabIndex=-1),n&&(this.setDefaultFocusedElement(n),n.tabIndex=0,this.hasFocus()&&n.focus())}breakpointAdded(e){this.addBreakpoint(e.data)}breakpointToggled(e){const t=this.hasFocus(),i=e.data;this.#a.refreshItem(i),t&&this.focus()}breakpointsRemoved(e){const t=this.hasFocus(),i=e.data;let n=-1;for(const e of i){const t=this.#o.indexOf(e);t>=0&&(this.#o.remove(t),n=t)}if(0===this.#o.length)this.#r.classList.remove("hidden"),this.setDefaultFocusedElement(this.#r),this.#a.element.classList.add("hidden");else if(n>=0){const e=this.#o.at(n);e&&this.#a.selectItem(e)}t&&this.focus()}addBreakpoint(e){this.#o.insertWithComparator(e,((e,t)=>e.type>t.type?-1:e.type<t.type?1:0)),this.#a.selectedItem()&&this.hasFocus()||this.#a.selectItem(this.#o.at(0))}contextMenu(e,t){const o=new i.ContextMenu.ContextMenu(t);o.defaultSection().appendItem(m(g.revealDomNodeInElementsPanel),(()=>n.Revealer.reveal(e.node))),o.defaultSection().appendItem(m(g.removeBreakpoint),(()=>{e.domDebuggerModel.removeDOMBreakpoint(e.node,e.type)})),o.defaultSection().appendItem(m(g.removeAllDomBreakpoints),(()=>{e.domDebuggerModel.removeAllDOMBreakpoints()})),o.show()}checkboxClicked(e,t){e.domDebuggerModel.toggleDOMBreakpoint(e,!!t.target&&t.target.checked)}flavorChanged(e){this.update()}update(){const t=i.Context.Context.instance().flavor(e.DebuggerModel.DebuggerPausedDetails);if(this.#l){const e=this.#l;this.#l=null,this.#a.refreshItem(e)}if(!t||!t.auxData||"DOM"!==t.reason)return;const n=t.debuggerModel.target().model(e.DOMDebuggerModel.DOMDebuggerModel);if(!n)return;const o=n.resolveDOMBreakpointData(t.auxData);if(o){for(const e of this.#o)e.node===o.node&&e.type===o.type&&(this.#l=e);this.#l&&this.#a.refreshItem(this.#l),i.ViewManager.ViewManager.instance().showView("sources.domBreakpoints")}}wasShown(){super.wasShown(),this.registerCSSFiles([k])}}const x=new Map([["subtree-modified",v(g.subtreeModified)],["attribute-modified",v(g.attributeModified)],["node-removed",v(g.nodeRemoved)]]);let B;class D{static instance(e={forceNew:null}){const{forceNew:t}=e;return B&&!t||(B=new D),B}appendApplicableItems(t,n,s){const r=s;if(r.pseudoType())return;const a=r.domModel().target().model(e.DOMDebuggerModel.DOMDebuggerModel);if(!a)return;function l(e){if(!a)return;const t=o.DebuggerPausedMessage.BreakpointTypeNouns.get(e),n=t?t():"";a.hasDOMBreakpoint(r,e)?(a.removeDOMBreakpoint(r,e),i.ARIAUtils.alert(`${m(g.breakpointRemoved)}: ${n}`)):(a.setDOMBreakpoint(r,e),i.ARIAUtils.alert(`${m(g.breakpointSet)}: ${n}`))}const d=n.debugSection().appendSubMenuItem(m(g.breakOn)),c={SubtreeModified:"subtree-modified",AttributeModified:"attribute-modified",NodeRemoved:"node-removed"};for(const e of Object.values(c)){const t=o.DebuggerPausedMessage.BreakpointTypeNouns.get(e);t&&d.defaultSection().appendCheckboxItem(t(),l.bind(null,e),a.hasDOMBreakpoint(r,e))}}}var E=Object.freeze({__proto__:null,DOMBreakpointsSidebarPane:f,ContextMenuProvider:D});let C;class w extends c{constructor(){let t=e.DOMDebuggerModel.DOMDebuggerManager.instance().eventListenerBreakpoints();const i=e.EventBreakpointsModel.EventBreakpointsManager.instance().eventListenerBreakpoints();t=t.concat(i);const n=t.map((e=>e.category()));n.sort(),super(n,t,"sources.eventListenerBreakpoints","EventListener")}static instance(){return C||(C=new w),C}getBreakpointFromPausedDetails(t){const i=t.auxData,n=e.DOMDebuggerModel.DOMDebuggerManager.instance().resolveEventListenerBreakpoint(i);return n||e.EventBreakpointsModel.EventBreakpointsManager.instance().resolveEventListenerBreakpoint(i)}}var L=Object.freeze({__proto__:null,EventListenerBreakpointsSidebarPane:w});const I={refreshGlobalListeners:"Refresh global listeners"},y=t.i18n.registerUIStrings("panels/browser_debugger/ObjectEventListenersSidebarPane.ts",I),O=t.i18n.getLocalizedString.bind(void 0,y);let S;class A extends i.Widget.VBox{#d;#c;#h;constructor(){super(),this.#d=new i.Toolbar.ToolbarButton(O(I.refreshGlobalListeners),"refresh"),this.#d.addEventListener(i.Toolbar.ToolbarButton.Events.Click,this.refreshClick,this),this.#d.setEnabled(!1),this.#c=new s.EventListenersView.EventListenersView(this.update.bind(this),!0),this.#c.show(this.element),this.setDefaultFocusedChild(this.#c)}static instance(){return S||(S=new A),S}get eventListenersView(){return this.#c}toolbarItems(){return[this.#d]}update(){this.#h&&(this.#h.runtimeModel.releaseObjectGroup(R),this.#h=void 0);const t=i.Context.Context.instance().flavor(e.RuntimeModel.ExecutionContext);if(!t)return this.#c.reset(),void this.#c.addEmptyHolderIfNeeded();this.#h=t,Promise.all([this.windowObjectInContext(t)]).then(this.#c.addObjects.bind(this.#c))}wasShown(){super.wasShown(),i.Context.Context.instance().addFlavorChangeListener(e.RuntimeModel.ExecutionContext,this.update,this),this.#d.setEnabled(!0),this.update()}willHide(){super.willHide(),i.Context.Context.instance().removeFlavorChangeListener(e.RuntimeModel.ExecutionContext,this.update,this),this.#d.setEnabled(!1)}windowObjectInContext(e){return e.evaluate({expression:"self",objectGroup:R,includeCommandLineAPI:!1,silent:!0,returnByValue:!1,generatePreview:!1},!1,!1).then((e=>"error"in e||e.exceptionDetails?null:e.object))}refreshClick(e){e.data.consume(),this.update()}}const R="object-event-listeners-sidebar-pane";var P=Object.freeze({__proto__:null,ObjectEventListenersSidebarPane:A,objectGroupName:R});const T=new CSSStyleSheet;T.replaceSync('.breakpoint-list{padding-bottom:3px}.breakpoint-list .editing.being-edited{overflow:hidden;white-space:nowrap}.breakpoint-condition{display:block;margin:4px 8px 4px 23px}.breakpoint-condition-input{display:block;margin-left:0;margin-right:0;outline:none!important;border:1px solid var(--color-background-elevation-2)}.breakpoint-entry{white-space:nowrap;padding:2px 0}.breakpoint-list .breakpoint-entry:hover{background-color:var(--color-background-elevation-1)}.breakpoint-list .breakpoint-entry:focus-visible{background-color:var(--legacy-focus-bg-color)}.breakpoint-entry [is="dt-checkbox"]{max-width:100%}.breakpoint-hit{--override-breakpoint-hit-background-color:rgb(255 255 194);--override-breakpoint-hit-border-color:rgb(107 97 48);background-color:var(--override-breakpoint-hit-background-color);border-right:3px solid var(--override-breakpoint-hit-border-color)}.-theme-with-dark-background .breakpoint-hit,\n:host-context(.-theme-with-dark-background) .breakpoint-hit{--override-breakpoint-hit-background-color:hsl(46deg 98% 22%);--override-breakpoint-hit-border-color:#ccc}@media (forced-colors: active){.breakpoint-list .breakpoint-entry:hover,\n  .breakpoint-list .breakpoint-entry:focus-visible{forced-color-adjust:none;background-color:Highlight}.breakpoint-list .breakpoint-entry:hover *,\n  .breakpoint-list .breakpoint-entry:focus-visible *{color:HighlightText}}\n/*# sourceURL=xhrBreakpointsSidebarPane.css */\n');const U={xhrfetchBreakpoints:"XHR/fetch Breakpoints",noBreakpoints:"No breakpoints",addXhrfetchBreakpoint:"Add XHR/fetch breakpoint",addBreakpoint:"Add breakpoint",breakWhenUrlContains:"Break when URL contains:",urlBreakpoint:"URL Breakpoint",urlContainsS:'URL contains "{PH1}"',anyXhrOrFetch:"Any XHR or fetch",breakpointHit:"breakpoint hit",removeAllBreakpoints:"Remove all breakpoints",removeBreakpoint:"Remove breakpoint"},H=t.i18n.registerUIStrings("panels/browser_debugger/XHRBreakpointsSidebarPane.ts",U),V=t.i18n.getLocalizedString.bind(void 0,H),F=new WeakMap,_=new WeakMap;let j;class X extends i.Widget.VBox{#o;#a;#r;#p;#b;#k;constructor(){super(!0),this.#o=new i.ListModel.ListModel,this.#a=new i.ListControl.ListControl(this.#o,this,i.ListControl.ListMode.NonViewport),this.contentElement.appendChild(this.#a.element),this.#a.element.classList.add("breakpoint-list","hidden"),i.ARIAUtils.markAsList(this.#a.element),i.ARIAUtils.setLabel(this.#a.element,V(U.xhrfetchBreakpoints)),this.#r=this.contentElement.createChild("div","gray-info-message"),this.#r.textContent=V(U.noBreakpoints),this.#p=new Map,this.#b=new i.Toolbar.ToolbarButton(V(U.addXhrfetchBreakpoint),"plus"),this.#b.addEventListener(i.Toolbar.ToolbarButton.Events.Click,(()=>{this.addButtonClicked()})),this.#r.addEventListener("contextmenu",this.emptyElementContextMenu.bind(this),!0),this.#r.tabIndex=-1,this.restoreBreakpoints(),this.update()}static instance(){return j||(j=new X),j}toolbarItems(){return[this.#b]}emptyElementContextMenu(e){const t=new i.ContextMenu.ContextMenu(e);t.defaultSection().appendItem(V(U.addBreakpoint),this.addButtonClicked.bind(this)),t.show()}async addButtonClicked(){await i.ViewManager.ViewManager.instance().showView("sources.xhrBreakpoints");const t=document.createElement("p");t.classList.add("breakpoint-condition"),t.textContent=V(U.breakWhenUrlContains);const n=t.createChild("span","breakpoint-condition-input");function o(i,n,o){this.removeListElement(t),i&&(e.DOMDebuggerModel.DOMDebuggerManager.instance().addXHRBreakpoint(o,!0),this.setBreakpoint(o)),this.update()}i.ARIAUtils.setLabel(n,V(U.urlBreakpoint)),this.addListElement(t,this.#a.element.firstChild);const s=new i.InplaceEditor.Config(o.bind(this,!0),o.bind(this,!1));i.InplaceEditor.InplaceEditor.startEditing(n,s)}heightForItem(e){return 0}isItemSelectable(e){return!0}setBreakpoint(e){-1!==this.#o.indexOf(e)?this.#a.refreshItem(e):this.#o.insertWithComparator(e,((e,t)=>e>t?1:e<t?-1:0)),this.#a.selectedItem()&&this.hasFocus()||this.#a.selectItem(this.#o.at(0))}createElementForItem(t){const n=document.createElement("div");i.ARIAUtils.markAsListitem(n);const o=n.createChild("div","breakpoint-entry");F.set(n,o);const s=e.DOMDebuggerModel.DOMDebuggerManager.instance().xhrBreakpoints().get(t)||!1;i.ARIAUtils.markAsCheckbox(o),i.ARIAUtils.setChecked(o,s),o.addEventListener("contextmenu",this.contextMenu.bind(this,t),!0);const r=t?V(U.urlContainsS,{PH1:t}):V(U.anyXhrOrFetch),a=i.UIUtils.CheckboxLabel.create(r,s);return i.ARIAUtils.markAsHidden(a),i.ARIAUtils.setLabel(o,r),o.appendChild(a),a.checkboxElement.addEventListener("click",this.checkboxClicked.bind(this,t,s),!1),o.addEventListener("click",(e=>{e.target===o&&this.checkboxClicked(t,s)}),!1),_.set(o,a.checkboxElement),a.checkboxElement.tabIndex=-1,o.tabIndex=-1,t===this.#a.selectedItem()&&(o.tabIndex=0,this.setDefaultFocusedElement(o)),o.addEventListener("keydown",(e=>{let i=!1;" "===e.key?(this.checkboxClicked(t,s),i=!0):"Enter"===e.key&&(this.labelClicked(t),i=!0),i&&e.consume(!0)})),t===this.#k&&(o.classList.add("breakpoint-hit"),i.ARIAUtils.setDescription(o,V(U.breakpointHit))),a.classList.add("cursor-auto"),a.textElement.addEventListener("dblclick",this.labelClicked.bind(this,t),!1),this.#p.set(t,n),n}selectedItemChanged(e,t,i,n){if(i){const e=F.get(i);if(!e)throw new Error("Expected breakpoint entry to be found for an element");e.tabIndex=-1}if(n){const e=F.get(n);if(!e)throw new Error("Expected breakpoint entry to be found for an element");this.setDefaultFocusedElement(e),e.tabIndex=0,this.hasFocus()&&e.focus()}}updateSelectedItemARIA(e,t){return!0}removeBreakpoint(e){const t=this.#o.indexOf(e);t>=0&&this.#o.remove(t),this.#p.delete(e),this.update()}addListElement(e,t){this.#a.element.insertBefore(e,t),this.#r.classList.add("hidden"),this.#a.element.classList.remove("hidden")}removeListElement(e){this.#a.element.removeChild(e),this.#a.element.firstElementChild||(this.#r.classList.remove("hidden"),this.#a.element.classList.add("hidden"))}contextMenu(t,n){const o=new i.ContextMenu.ContextMenu(n);const s=V(U.removeAllBreakpoints);o.defaultSection().appendItem(V(U.addBreakpoint),this.addButtonClicked.bind(this)),o.defaultSection().appendItem(V(U.removeBreakpoint),function(){e.DOMDebuggerModel.DOMDebuggerManager.instance().removeXHRBreakpoint(t),this.removeBreakpoint(t)}.bind(this)),o.defaultSection().appendItem(s,function(){for(const t of this.#p.keys())e.DOMDebuggerModel.DOMDebuggerManager.instance().removeXHRBreakpoint(t),this.removeBreakpoint(t);this.update()}.bind(this)),o.show()}checkboxClicked(t,i){const n=this.hasFocus();e.DOMDebuggerModel.DOMDebuggerManager.instance().toggleXHRBreakpoint(t,!i),this.#a.refreshItem(t),this.#a.selectItem(t),n&&this.focus()}labelClicked(t){const n=this.#p.get(t),o=document.createElement("span");function s(i,s,r){if(this.removeListElement(o),i){e.DOMDebuggerModel.DOMDebuggerManager.instance().removeXHRBreakpoint(t),this.removeBreakpoint(t);let i=!0;if(n){const e=F.get(n),t=e?_.get(e):void 0;t&&(i=t.checked)}e.DOMDebuggerModel.DOMDebuggerManager.instance().addXHRBreakpoint(r,i),this.setBreakpoint(r),this.#a.selectItem(r)}else n&&n.classList.remove("hidden");this.focus()}o.classList.add("breakpoint-condition"),o.textContent=t,n&&(this.#a.element.insertBefore(o,n),n.classList.add("hidden"));const r=new i.InplaceEditor.Config(s.bind(this,!0),s.bind(this,!1));i.InplaceEditor.InplaceEditor.startEditing(o,r)}flavorChanged(e){this.update()}update(){const t=0===this.#o.length;this.#a.element.classList.toggle("hidden",t),this.#r.classList.toggle("hidden",!t);const n=i.Context.Context.instance().flavor(e.DebuggerModel.DebuggerPausedDetails);if(!n||"XHR"!==n.reason){if(this.#k){const e=this.#k;this.#k=void 0,this.#o.indexOf(e)>=0&&this.#a.refreshItem(e)}return}const o=n.auxData&&n.auxData.breakpointURL;this.#k=o,this.#o.indexOf(o)<0||(this.#a.refreshItem(o),i.ViewManager.ViewManager.instance().showView("sources.xhrBreakpoints"))}restoreBreakpoints(){const t=e.DOMDebuggerModel.DOMDebuggerManager.instance().xhrBreakpoints();for(const e of t.keys())this.setBreakpoint(e)}wasShown(){super.wasShown(),this.registerCSSFiles([T])}}var z=Object.freeze({__proto__:null,XHRBreakpointsSidebarPane:X});export{b as CSPViolationBreakpointsSidebarPane,E as DOMBreakpointsSidebarPane,L as EventListenerBreakpointsSidebarPane,P as ObjectEventListenersSidebarPane,z as XHRBreakpointsSidebarPane};
